import {
  reqHomeHospitalCardListsData,
  reqHomeHospitalTabLevelData
} from '@/service/modules/home'
import type {
  IHomeHospitalLevelArr,
  IHomeHospitalCardListData
} from '@/service/modules/home/type'
import { defineStore } from 'pinia'

interface IStateHome {
  hospitalLevelArr?: IHomeHospitalLevelArr
  hospitalAreaArr?: IHomeHospitalLevelArr
  hospitalCardData?: IHomeHospitalCardListData
}

export const useHomeStore = defineStore('home', {
  state: (): IStateHome => ({
    hospitalLevelArr: [],
    hospitalAreaArr: [],
    hospitalCardData: {}
  }),
  actions: {
    // home 医院等级与地区的类型
    // fetchHomeData() {
    //   // 医院等级
    //   this.fetchHospitalTabAllData()
    //   this.fetchHospitalCardListAction(1, 3)
    // },

    async fecthHospitalLevelAction(dictCode: string) {
      const res = await reqHomeHospitalTabLevelData(dictCode)
      if (res?.code === 200) {
        return res.data
      }
    },
    fetchHospitalTabAllData() {
      this.fecthHospitalLevelAction('HosType').then((res) => {
        this.hospitalLevelArr = res
      })
      this.fecthHospitalLevelAction('beijin').then((res) => {
        this.hospitalAreaArr = res
      })
    },
    async fetchHospitalCardListAction(
      page: number,
      limit: number,
      hostype?: string,
      districtCode?: string
    ) {
      const res = await reqHomeHospitalCardListsData(
        page,
        limit,
        hostype,
        districtCode
      )
      if (res.code === 200) {
        this.hospitalCardData = res.data
      }
    }

    // 分页
  }
})
